<?php
global $Config;
require_once($Config->WebCMSRoot.'Base/Control.php');
require_once($Config->WebCMSRoot.'Models/Map.php');
require_once($Config->WebCMSRoot.'Views/Map.php');

/*
	Uses Google Maps API
	
	Request Key: 
		http://www.google.com/apis/maps/signup.html
		
	Documentation:
		http://www.google.com/apis/maps/documentation/reference.html
		
	Examples:
		http://www.google.com/apis/maps/documentation/index.html
	
	Retrieve coordinates:
		http://maps.google.com/maps/geo?q=kempenlaan+12,2920+kalmthout,belgie&key=ABQIAAAAKqFGUfhdMhQjYgy9gCLlPRRCsaOO_tVem4fQsU9L0SBrt3bukxQtEmsdpuIbWfSi2T7TZ8gQl9_eSA&output=csv
*/
Class Map extends BaseControl
{
	var $view;
	var $APIkey;
	
	var $map;

	function Map($parameters, &$page)
	{
		$this->APIkey = '';

		$this->map  = new MapModel();
		$this->view = new MapView();

		parent::BaseControl($parameters, &$page);
	}

	function Execute()
	{
		$this->APIkey = $this->GetParameter('apiKey');

		/*switch ($this->GetParameter('show'))
		{
			case 'map':*/
				$this->map->Retrieve(&$this->parameters);
				if (count($this->map->Collection) > 0)
				{
					$width = $this->ParameterExists('width') ? $this->GetParameter('width') : 760;
					$height = $this->ParameterExists('height') ? $this->GetParameter('height') : 450;
					$this->view->ShowMap($this->map->Collection[0], $this->APIkey, $width, $height);
				}
				/*break;
		}*/

		parent::Execute();
	}

	function ValidateArguments($args)
	{
		$valid = false;
		$argCount = 2;
		
		if ($this->ParameterExists('width') && $this->ParameterExists('height'))
		{
			$argCount += 2;
		}

		/*switch ($this->GetParameter('show'))
		{
			case 'index':*/
				$valid = (count($args) == $argCount);
				$valid = $valid && $this->ParameterExists('apiKey');
				/*break;
			case 'post':
				$valid = (count($args) == 2);
				break;
		}*/

		return $valid;
	}
}
?>